package subject_set.offer100;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author haomin
 * @date 2022/10/15 10:34
 **/
public class Offer27 {
    class Solution {
        public TreeNode mirrorTree(TreeNode root) {
            if(root == null) return null;
            TreeNode l = root.left;
            TreeNode r = root.right;
            root.left = r;
            root.right = l;
            mirrorTree(root.left);
            mirrorTree(root.right);
            return root;
        }
    }
    class Solution2 {
        public TreeNode mirrorTree(TreeNode root) {
            if(root == null) return root;
            Deque<TreeNode> queue = new LinkedList<>();
            queue.add(root);
            while(!queue.isEmpty()){
                TreeNode cur = queue.poll();
                TreeNode tmp = cur.left;
                cur.left = cur.right;
                cur.right = tmp;
                if(cur.left != null) queue.add(cur.left);
                if(cur.right != null) queue.add(cur.right);

            }
            return root;
        }
    }
}